package hutool.http;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.*;
import spring.jackson.JacksonJsonUtil;

import java.util.HashMap;
import java.util.Map;

public class HttpRequestData {

    public static void main(String[] args) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("appCode", "xxxxx"); //appCode
        String s = HttpUtil.post("https://arp.caas.cn/pbs/api/token/create", paramMap);
        HashMap<String, Object> tokenResult = JacksonJsonUtil.toObject(s, HashMap.class);
        String token = MapUtil.getStr(MapUtil.get(tokenResult, "data", HashMap.class), "token");
        paramMap = new HashMap<>();
        paramMap.put("flag", ""); //flag 标识
        paramMap.put("beginTime", ""); //开始时间
        paramMap.put("endTime", ""); //结束时间
        paramMap.put("page", "1"); //页码
        paramMap.put("limit", "1"); //每页数量 默认20
        HttpRequest request = HttpUtil.createPost("https://arp.caas.cn/pbs/api/arpdata/query");
        request.header("token", token).header(Header.CONTENT_TYPE, ContentType.FORM_URLENCODED.toString(CharsetUtil.CHARSET_UTF_8)).form(paramMap);
        HttpResponse response = request.execute();
        System.out.println(response);
        s = response.body();
        System.out.println(s);
    }

}
